{
 "metadata": {
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.1-final"
  },
  "orig_nbformat": 2,
  "kernelspec": {
   "name": "Python 3.7.1 64-bit ('base': conda)",
   "display_name": "Python 3.7.1 64-bit ('base': conda)",
   "metadata": {
    "interpreter": {
     "hash": "2266c607543d224cb119288ea55888d6fda87cc9a4c78c02ed099d39082a76ce"
    }
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2,
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "Wall time: 3.36 s\n"
     ]
    }
   ],
   "source": [
    "from pdb_profiling import default_config\n",
    "\n",
    "%time default_config(\"C:/GitWorks/pdb-profiling/test/demo\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "from pdb_profiling.processors import PDB, SIFTS, PDBs, SIFTSs"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "Wall time: 5.11 s\n"
     ]
    },
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "   UniProt chain_id  entity_id  identity  is_canonical pdb_id struct_asym_id  \\\n",
       "19  O15350        B          2      0.98          True   2nb1              B   \n",
       "26  O15350        A          1      1.00          True   1cok              A   \n",
       "60  O15350        A          1      1.00          True   4a63              A   \n",
       "\n",
       "    pdb_range    unp_range   Entry  ... resolution experimental_method_class  \\\n",
       "19   [[3,50]]  [[351,398]]  O15350  ...        NaN                       nmr   \n",
       "26   [[1,68]]  [[487,554]]  O15350  ...        NaN                       nmr   \n",
       "60  [[2,201]]  [[112,311]]  O15350  ...       2.27                     x-ray   \n",
       "\n",
       "    experimental_method  multi_method  revision_date deposition_date  \\\n",
       "19         Solution NMR         False       20171122        20160119   \n",
       "26         Solution NMR         False       20110713        19990528   \n",
       "60    X-ray diffraction         False       20180124        20111031   \n",
       "\n",
       "   1/resolution id_score  COV_SCORE select_tag  \n",
       "19          NaN      -66   0.136752       True  \n",
       "26          NaN      -65   0.193732       True  \n",
       "60     0.440529      -65   0.545352       True  \n",
       "\n",
       "[3 rows x 47 columns]"
      ],
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>UniProt</th>\n      <th>chain_id</th>\n      <th>entity_id</th>\n      <th>identity</th>\n      <th>is_canonical</th>\n      <th>pdb_id</th>\n      <th>struct_asym_id</th>\n      <th>pdb_range</th>\n      <th>unp_range</th>\n      <th>Entry</th>\n      <th>...</th>\n      <th>resolution</th>\n      <th>experimental_method_class</th>\n      <th>experimental_method</th>\n      <th>multi_method</th>\n      <th>revision_date</th>\n      <th>deposition_date</th>\n      <th>1/resolution</th>\n      <th>id_score</th>\n      <th>COV_SCORE</th>\n      <th>select_tag</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>19</th>\n      <td>O15350</td>\n      <td>B</td>\n      <td>2</td>\n      <td>0.98</td>\n      <td>True</td>\n      <td>2nb1</td>\n      <td>B</td>\n      <td>[[3,50]]</td>\n      <td>[[351,398]]</td>\n      <td>O15350</td>\n      <td>...</td>\n      <td>NaN</td>\n      <td>nmr</td>\n      <td>Solution NMR</td>\n      <td>False</td>\n      <td>20171122</td>\n      <td>20160119</td>\n      <td>NaN</td>\n      <td>-66</td>\n      <td>0.136752</td>\n      <td>True</td>\n    </tr>\n    <tr>\n      <th>26</th>\n      <td>O15350</td>\n      <td>A</td>\n      <td>1</td>\n      <td>1.00</td>\n      <td>True</td>\n      <td>1cok</td>\n      <td>A</td>\n      <td>[[1,68]]</td>\n      <td>[[487,554]]</td>\n      <td>O15350</td>\n      <td>...</td>\n      <td>NaN</td>\n      <td>nmr</td>\n      <td>Solution NMR</td>\n      <td>False</td>\n      <td>20110713</td>\n      <td>19990528</td>\n      <td>NaN</td>\n      <td>-65</td>\n      <td>0.193732</td>\n      <td>True</td>\n    </tr>\n    <tr>\n      <th>60</th>\n      <td>O15350</td>\n      <td>A</td>\n      <td>1</td>\n      <td>1.00</td>\n      <td>True</td>\n      <td>4a63</td>\n      <td>A</td>\n      <td>[[2,201]]</td>\n      <td>[[112,311]]</td>\n      <td>O15350</td>\n      <td>...</td>\n      <td>2.27</td>\n      <td>x-ray</td>\n      <td>X-ray diffraction</td>\n      <td>False</td>\n      <td>20180124</td>\n      <td>20111031</td>\n      <td>0.440529</td>\n      <td>-65</td>\n      <td>0.545352</td>\n      <td>True</td>\n    </tr>\n  </tbody>\n</table>\n<p>3 rows × 47 columns</p>\n</div>"
     },
     "metadata": {},
     "execution_count": 3
    }
   ],
   "source": [
    "%time df = SIFTS('O15350').pipe_select_mo().result()\n",
    "df[df.select_tag.eq(True)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "[<SIFTS UniProt O15350>, <SIFTS UniProt O15350-2>, <SIFTS UniProt Q8N2K1-3>]"
      ]
     },
     "metadata": {},
     "execution_count": 4
    }
   ],
   "source": [
    "sifts = SIFTSs(('O15350', 'O15350-2', 'Q8N2K1-3'))\n",
    "sifts"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "res = sifts.fetch('pipe_select_mo').run().result()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "    UniProt chain_id  entity_id  identity  is_canonical pdb_id struct_asym_id  \\\n",
       "0  Q8N2K1-3        A          1      0.92         False   2f4w              A   \n",
       "1  Q8N2K1-3        B          1      0.92         False   2f4w              B   \n",
       "\n",
       "   pdb_range  unp_range   Entry  ... resolution experimental_method_class  \\\n",
       "0  [[3,187]]  [[1,201]]  Q8N2K1  ...          2                     x-ray   \n",
       "1  [[3,187]]  [[1,201]]  Q8N2K1  ...          2                     x-ray   \n",
       "\n",
       "   experimental_method  multi_method  revision_date deposition_date  \\\n",
       "0    X-ray diffraction         False       20121128        20051124   \n",
       "1    X-ray diffraction         False       20121128        20051124   \n",
       "\n",
       "  1/resolution id_score  COV_SCORE select_tag  \n",
       "0          0.5      -65   0.026928      False  \n",
       "1          0.5      -66   0.102353       True  \n",
       "\n",
       "[2 rows x 47 columns]"
      ],
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>UniProt</th>\n      <th>chain_id</th>\n      <th>entity_id</th>\n      <th>identity</th>\n      <th>is_canonical</th>\n      <th>pdb_id</th>\n      <th>struct_asym_id</th>\n      <th>pdb_range</th>\n      <th>unp_range</th>\n      <th>Entry</th>\n      <th>...</th>\n      <th>resolution</th>\n      <th>experimental_method_class</th>\n      <th>experimental_method</th>\n      <th>multi_method</th>\n      <th>revision_date</th>\n      <th>deposition_date</th>\n      <th>1/resolution</th>\n      <th>id_score</th>\n      <th>COV_SCORE</th>\n      <th>select_tag</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>Q8N2K1-3</td>\n      <td>A</td>\n      <td>1</td>\n      <td>0.92</td>\n      <td>False</td>\n      <td>2f4w</td>\n      <td>A</td>\n      <td>[[3,187]]</td>\n      <td>[[1,201]]</td>\n      <td>Q8N2K1</td>\n      <td>...</td>\n      <td>2</td>\n      <td>x-ray</td>\n      <td>X-ray diffraction</td>\n      <td>False</td>\n      <td>20121128</td>\n      <td>20051124</td>\n      <td>0.5</td>\n      <td>-65</td>\n      <td>0.026928</td>\n      <td>False</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>Q8N2K1-3</td>\n      <td>B</td>\n      <td>1</td>\n      <td>0.92</td>\n      <td>False</td>\n      <td>2f4w</td>\n      <td>B</td>\n      <td>[[3,187]]</td>\n      <td>[[1,201]]</td>\n      <td>Q8N2K1</td>\n      <td>...</td>\n      <td>2</td>\n      <td>x-ray</td>\n      <td>X-ray diffraction</td>\n      <td>False</td>\n      <td>20121128</td>\n      <td>20051124</td>\n      <td>0.5</td>\n      <td>-66</td>\n      <td>0.102353</td>\n      <td>True</td>\n    </tr>\n  </tbody>\n</table>\n<p>2 rows × 47 columns</p>\n</div>"
     },
     "metadata": {},
     "execution_count": 6
    }
   ],
   "source": [
    "res[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "from tqdm import tqdm"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "output_type": "stream",
     "name": "stderr",
     "text": [
      "100%|██████████| 3/3 [00:07<00:00,  2.38s/it]\n"
     ]
    }
   ],
   "source": [
    "res = sifts.fetch('pipe_select_mo').run(tqdm).result()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "from pandas import concat"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "    UniProt chain_id  entity_id  identity  is_canonical pdb_id struct_asym_id  \\\n",
       "0    O15350        B          2      0.98          True   2nb1              B   \n",
       "1    O15350        A          1      1.00          True   1cok              A   \n",
       "2    O15350        A          1      1.00          True   4a63              A   \n",
       "3  Q8N2K1-3        B          1      0.92         False   2f4w              B   \n",
       "4  O15350-2        A          1      1.00         False   4a63              A   \n",
       "5  O15350-2        B          2      0.98         False   2nb1              B   \n",
       "\n",
       "   pdb_range    unp_range   Entry  ... resolution experimental_method_class  \\\n",
       "0   [[3,50]]  [[351,398]]  O15350  ...        NaN                       nmr   \n",
       "1   [[1,68]]  [[487,554]]  O15350  ...        NaN                       nmr   \n",
       "2  [[2,201]]  [[112,311]]  O15350  ...       2.27                     x-ray   \n",
       "3  [[3,187]]    [[1,201]]  Q8N2K1  ...       2.00                     x-ray   \n",
       "4  [[2,201]]  [[112,311]]  O15350  ...       2.27                     x-ray   \n",
       "5   [[3,50]]  [[351,398]]  O15350  ...        NaN                       nmr   \n",
       "\n",
       "   experimental_method  multi_method  revision_date deposition_date  \\\n",
       "0         Solution NMR         False       20171122        20160119   \n",
       "1         Solution NMR         False       20110713        19990528   \n",
       "2    X-ray diffraction         False       20180124        20111031   \n",
       "3    X-ray diffraction         False       20121128        20051124   \n",
       "4    X-ray diffraction         False       20180124        20111031   \n",
       "5         Solution NMR         False       20171122        20160119   \n",
       "\n",
       "  1/resolution id_score  COV_SCORE select_tag  \n",
       "0          NaN      -66   0.136752       True  \n",
       "1          NaN      -65   0.193732       True  \n",
       "2     0.440529      -65   0.545352       True  \n",
       "3     0.500000      -66   0.102353       True  \n",
       "4     0.440529      -65   0.739068       True  \n",
       "5          NaN      -66   0.185328       True  \n",
       "\n",
       "[6 rows x 47 columns]"
      ],
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>UniProt</th>\n      <th>chain_id</th>\n      <th>entity_id</th>\n      <th>identity</th>\n      <th>is_canonical</th>\n      <th>pdb_id</th>\n      <th>struct_asym_id</th>\n      <th>pdb_range</th>\n      <th>unp_range</th>\n      <th>Entry</th>\n      <th>...</th>\n      <th>resolution</th>\n      <th>experimental_method_class</th>\n      <th>experimental_method</th>\n      <th>multi_method</th>\n      <th>revision_date</th>\n      <th>deposition_date</th>\n      <th>1/resolution</th>\n      <th>id_score</th>\n      <th>COV_SCORE</th>\n      <th>select_tag</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>O15350</td>\n      <td>B</td>\n      <td>2</td>\n      <td>0.98</td>\n      <td>True</td>\n      <td>2nb1</td>\n      <td>B</td>\n      <td>[[3,50]]</td>\n      <td>[[351,398]]</td>\n      <td>O15350</td>\n      <td>...</td>\n      <td>NaN</td>\n      <td>nmr</td>\n      <td>Solution NMR</td>\n      <td>False</td>\n      <td>20171122</td>\n      <td>20160119</td>\n      <td>NaN</td>\n      <td>-66</td>\n      <td>0.136752</td>\n      <td>True</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>O15350</td>\n      <td>A</td>\n      <td>1</td>\n      <td>1.00</td>\n      <td>True</td>\n      <td>1cok</td>\n      <td>A</td>\n      <td>[[1,68]]</td>\n      <td>[[487,554]]</td>\n      <td>O15350</td>\n      <td>...</td>\n      <td>NaN</td>\n      <td>nmr</td>\n      <td>Solution NMR</td>\n      <td>False</td>\n      <td>20110713</td>\n      <td>19990528</td>\n      <td>NaN</td>\n      <td>-65</td>\n      <td>0.193732</td>\n      <td>True</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>O15350</td>\n      <td>A</td>\n      <td>1</td>\n      <td>1.00</td>\n      <td>True</td>\n      <td>4a63</td>\n      <td>A</td>\n      <td>[[2,201]]</td>\n      <td>[[112,311]]</td>\n      <td>O15350</td>\n      <td>...</td>\n      <td>2.27</td>\n      <td>x-ray</td>\n      <td>X-ray diffraction</td>\n      <td>False</td>\n      <td>20180124</td>\n      <td>20111031</td>\n      <td>0.440529</td>\n      <td>-65</td>\n      <td>0.545352</td>\n      <td>True</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>Q8N2K1-3</td>\n      <td>B</td>\n      <td>1</td>\n      <td>0.92</td>\n      <td>False</td>\n      <td>2f4w</td>\n      <td>B</td>\n      <td>[[3,187]]</td>\n      <td>[[1,201]]</td>\n      <td>Q8N2K1</td>\n      <td>...</td>\n      <td>2.00</td>\n      <td>x-ray</td>\n      <td>X-ray diffraction</td>\n      <td>False</td>\n      <td>20121128</td>\n      <td>20051124</td>\n      <td>0.500000</td>\n      <td>-66</td>\n      <td>0.102353</td>\n      <td>True</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>O15350-2</td>\n      <td>A</td>\n      <td>1</td>\n      <td>1.00</td>\n      <td>False</td>\n      <td>4a63</td>\n      <td>A</td>\n      <td>[[2,201]]</td>\n      <td>[[112,311]]</td>\n      <td>O15350</td>\n      <td>...</td>\n      <td>2.27</td>\n      <td>x-ray</td>\n      <td>X-ray diffraction</td>\n      <td>False</td>\n      <td>20180124</td>\n      <td>20111031</td>\n      <td>0.440529</td>\n      <td>-65</td>\n      <td>0.739068</td>\n      <td>True</td>\n    </tr>\n    <tr>\n      <th>5</th>\n      <td>O15350-2</td>\n      <td>B</td>\n      <td>2</td>\n      <td>0.98</td>\n      <td>False</td>\n      <td>2nb1</td>\n      <td>B</td>\n      <td>[[3,50]]</td>\n      <td>[[351,398]]</td>\n      <td>O15350</td>\n      <td>...</td>\n      <td>NaN</td>\n      <td>nmr</td>\n      <td>Solution NMR</td>\n      <td>False</td>\n      <td>20171122</td>\n      <td>20160119</td>\n      <td>NaN</td>\n      <td>-66</td>\n      <td>0.185328</td>\n      <td>True</td>\n    </tr>\n  </tbody>\n</table>\n<p>6 rows × 47 columns</p>\n</div>"
     },
     "metadata": {},
     "execution_count": 10
    }
   ],
   "source": [
    "concat((df[df.select_tag.eq(True)] for df in res), sort=False, ignore_index=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ]
}